<?php
class UrlController extends ManagerController {
	public function UrlController(){
		parent::ManagerController();
	}
	
	/**
	 * 重新统计本站的所有链接
	 */
	public function reflash(){
		$urls = array('_id' => SITE_ID);
		
		$urls['items'][] = array(
			'id' => '',
			'url' => '/login.html',
			'model' => 'user',
			'app' => 'site',
			'act' => 'login',
		);
		$urls['items'][] = array(
			'id' => '',
			'url' => '/logout.html',
			'model' => 'user',
			'app' => 'site',
			'act' => 'logout',
		);
		$urls['items'][] = array(
			'id' => '',
			'url' => '/regist.html',
			'model' => 'user',
			'app' => 'site',
			'act' => 'regist',
		);
		
		//统计文章分类模块
		$ac_mod = new Article_cateModel();
		$acates = $ac_mod->find(array('site_id'=>SITE_ID), 'path');
		$cates = array();
		foreach($acates as $id=>$acate){
			$cates[$id] = $acate['path'];
			$urls['items'][] = array(
				'id' => $acate['_id'],
				'url' => $acate['path'] . '/' . 'index.html',
				'model' => 'article_cate',
				'app' => 'article',
				'act' => 'cate',
			);
			echo $id . '=>' . $acate['path'] . '/' . 'index.html' . '<br>';
		}
		
		//文章模块
		$a_mod = new ArticleModel();
		$as = $a_mod->find(array('site_id'=>SITE_ID), 'alias,cate');
		foreach($as as $a){
			if(is_array($a['cate'])){
				foreach ($a['cate'] as $c){
					$cate_path = $cates[$c];
					init_article_url($a, $cate_path);
					$urls['items'][] = array(
						'id' => $a['_id'],
						'model' => 'article',
						'app' => 'article',
						'act' => 'view',
						'url' => $a['url'],
					);
					echo $c . '=>' . $a['url'] . '<br>';
				}
			}else{
				$cate_path = $cates[$a['cate']];
				init_article_url($a, $cate_path);
				$urls['items'][] = array(
						'id' => $a['_id'],
						'model' => 'article',
						'app' => 'article',
						'act' => 'view',
						'url' => $a['url'],
				);
				echo $a['cate'] . '=>' . $a['url'] . '<br>';
			}
		}
		$url_mod = new UrlModel();
		$url_mod->delete_by_key(SITE_ID);
		$url_mod->insert($urls);
	}
}

?>